//
//  WYPopPlanView.m
//  renxinghuan
//
//  Created by admin on 2018/5/3.
//  Copyright © 2018年 吴清翠. All rights reserved.
//

#import "WYPopPlanView.h"
#import <Masonry.h>
#import "WYPopPlanCell.h"
#import "WYCSelectionModel.h"
@interface WYPopPlanView()<UITableViewDelegate,UITableViewDataSource>


@end
@implementation WYPopPlanView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self createSubViews];
        self.backgroundColor = [UIColor whiteColor];
    }
    return self;
    
    
    
    
}

-(void)createSubViews
{
    UIView *topView = [[UIView alloc]init];
    [self addSubview:topView];
    
    [topView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_equalTo(0);
        make.height.mas_equalTo(40);
    }];
    
    UIView *lineView = [[UIView alloc]init];
    [topView addSubview:lineView];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_equalTo(0);
        make.height.mas_equalTo(1/[UIScreen mainScreen].scale);
    }];
    
    lineView.backgroundColor = [UIColor colorWithRed:64/255.0 green:147/255.0 blue:214/255.0 alpha:1.0];
    
    
    
    
    UILabel *titleLabel = [[UILabel alloc]init];
    [topView addSubview:titleLabel];
    
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.mas_equalTo(topView);
    }];
    
    titleLabel.textColor = [UIColor colorWithRed:64/255.0 green:147/255.0 blue:214/255.0 alpha:1.0];
    titleLabel.font = [UIFont systemFontOfSize:18];
    titleLabel.text=@"选择消费计划";
    UITableView *tableView = [[UITableView alloc]init];
    self.tableView = tableView;
    
    tableView.delegate = self;
    tableView.dataSource = self;
    
    [self addSubview:tableView];
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(40);
        make.left.right.bottom.mas_equalTo(0);
    }];
    [tableView registerNib:[UINib nibWithNibName:@"WYPopPlanCell" bundle:nil] forCellReuseIdentifier:@"WYPopPlanCell"];
    tableView.tableFooterView = [[UIView alloc]init];
}


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
    
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYPopPlanCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WYPopPlanCell" forIndexPath:indexPath];
    if (!cell) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"WYPopPlanCell" owner:nil options:nil].firstObject;
    }
//     NSString * strmax = [NSString stringWithFormat:@"计划%ld 日消费%@笔     消费金额%@-%@",(long)component,model.maxNumber,model.minAmount,model.maxAmount];
    WYCSelectionModel *model =self.dataArray[indexPath.row];
    cell.consumptionLabel.text = [NSString stringWithFormat:@"%@",model.planName];
    cell.countLabel.text = [NSString stringWithFormat:@"日消费%@笔",model.maxNumber];
    cell.priceLabel.text = [NSString stringWithFormat:@"消费金额%@-%@",model.minAmount,model.maxAmount];
    return cell;
}


-(void)setDataArray:(NSArray *)dataArray
{
    _dataArray = dataArray;
    [self.tableView reloadData];
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    WYCSelectionModel *model =self.dataArray[indexPath.row];
    
    
    if ([self.delegate respondsToSelector:@selector(clickPlan:)]) {
        [self.delegate clickPlan:model];
    }
    
    
    
    NSLog(@"dasdsadsadasdas");
}



@end
